package com.jiayinlending.jiayindai.fragment;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiayinlending.jiayindai.R;
import com.jiayinlending.jiayindai.activity.mine.PerfectInformationActivity;
import com.jiayinlending.jiayindai.activity.mine.information.PersonalInformationActivity;
import com.jiayinlending.jiayindai.activity.mine.loanrecord.LoanRecordActivity;
import com.jiayinlending.jiayindai.activity.mine.mybill.MyBillActivity;
import com.jiayinlending.jiayindai.activity.myrepay.MyLoanActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xiaohei on 2017/3/28.
 */

public class MineFragment extends Fragment {
    @Bind(R.id.rl_myloan)
    RelativeLayout rlMyloan;
    @Bind(R.id.bt_perfectInformatin)
    Button btPerfectInformatin;
    @Bind(R.id.ll_personal)
    LinearLayout llPersonal;
    @Bind(R.id.rl_loan_record)
    RelativeLayout rlLoanRecord;
    private View mRootView;


    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (mRootView != null) {
            return mRootView;

        } else {
            mRootView = inflater.inflate(R.layout.fragment_mine, container, false);
            ViewGroup parent = (ViewGroup) mRootView.getParent();
            if (parent != null) {
                parent.removeView(mRootView);
            }
        }
        initTitleView();
        ButterKnife.bind(this, mRootView);
        return mRootView;
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    private void initTitleView() {
        TextView toolbar_title = (TextView) mRootView.findViewById(R.id.toolbar_title);
        TextView toolbar_subtitle = (TextView) mRootView.findViewById(R.id.toolbar_subtitle);
        toolbar_subtitle.setText("");
        toolbar_subtitle.setBackground(getResources().getDrawable(R.mipmap.ic_message));
        toolbar_title.setText("我的");
        toolbar_subtitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), MyBillActivity.class));
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.ll_personal, R.id.rl_myloan, R.id.rl_loan_record, R.id.bt_perfectInformatin})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_personal:
                startActivity(new Intent(getActivity(), PersonalInformationActivity.class));
                break;
            case R.id.rl_myloan:
                Intent intent = new Intent(getActivity(), MyLoanActivity.class);
                startActivity(intent);
                break;
            case R.id.rl_loan_record:
                startActivity(new Intent(getActivity(), LoanRecordActivity.class));
                break;
            case R.id.bt_perfectInformatin:
                startActivity(new Intent(getActivity(), PerfectInformationActivity.class));
                break;
        }
    }

}

